package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizUserDevice;
import com.member.shop.service.ISysBizUserDeviceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 【用户设备】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-10-28
 **/
@RestController
@RequestMapping("/shop/userDevice")
public class SysBizUserDeviceController extends BaseController {
    @Resource
    private ISysBizUserDeviceService sysBizUserDeviceService;

    /**
     * 查询用户设备列表
     */
    @PreAuthorize("@ss.hasPermi('shop:userDevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizUserDevice sysBizUserDevice) {
        startPage();

        List<SysBizUserDevice> list = sysBizUserDeviceService.selectSysBizUserDeviceList(sysBizUserDevice);
        return getDataTable(list);
    }

    /**
     * 导出用户设备列表
     */
    @PreAuthorize("@ss.hasPermi('shop:userDevice:export')")
    @Log(title = "用户设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizUserDevice sysBizUserDevice) {

        List<SysBizUserDevice> list = sysBizUserDeviceService.selectSysBizUserDeviceList(sysBizUserDevice);
        ExcelUtil<SysBizUserDevice> util = new ExcelUtil<SysBizUserDevice>(SysBizUserDevice.class);
        util.exportExcel(response, list, "用户设备数据");
    }

    /**
     * 获取用户设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:userDevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizUserDeviceService.selectSysBizUserDeviceById(id));
    }

    /**
     * 新增用户设备
     */
    @PreAuthorize("@ss.hasPermi('shop:userDevice:add')")
    @Log(title = "用户设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizUserDevice sysBizUserDevice) {
        sysBizUserDevice.setAuditor(getUserId());
        sysBizUserDevice.setAuditTime(LocalDateTime.now());
        return toAjax(sysBizUserDeviceService.insertSysBizUserDevice(sysBizUserDevice));
    }

    /**
     * 修改用户设备
     */
    @PreAuthorize("@ss.hasPermi('shop:userDevice:edit')")
    @Log(title = "用户设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizUserDevice sysBizUserDevice) {
        sysBizUserDevice.setAuditor(getUserId());
        sysBizUserDevice.setAuditTime(LocalDateTime.now());
        return toAjax(sysBizUserDeviceService.updateSysBizUserDevice(sysBizUserDevice));
    }

    /**
     * 删除用户设备
     */
    @PreAuthorize("@ss.hasPermi('shop:userDevice:remove')")
    @Log(title = "用户设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizUserDeviceService.deleteSysBizUserDeviceByIds(ids));
    }
}
